package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/kordar/ginsys/util"
	response "github.com/kordar/goframework_resp"
	form2 "labelsys/dataset/form"
	"labelsys/dataset/service"
)

type DatasetController struct {
	uploadService service.DatasetUploadService
}

func NewDatasetController(uploadService service.DatasetUploadService) *DatasetController {
	return &DatasetController{uploadService: uploadService}
}

func (c *DatasetController) Upload(ctx *gin.Context) {
	f := form2.UploadForm{}
	if err := util.DefaultGetValidParams(ctx, &f); err != nil {
		response.Error(ctx, err, nil)
		return
	}

	err, data := c.uploadService.Upload(f, ctx)
	if err != nil {
		response.Error(ctx, err, nil)
		return
	}

	response.Success(ctx, "", data)
}
